package edu.ynmd.parm.action;

import edu.ynmd.parm.model.Student;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;


@Controller
public class PublicAction {


    @RequestMapping("getAnString")
    @ResponseBody
    public String getAnString(){
        return "服务器端返回的字符窜";
    }


    //?key=value
//http://localhost/passValueToServrByRequestParm?sid=abc123
    @GetMapping("passValueToServrByRequestParm")
    @ResponseBody
    public String passVaueToServeByRequestParm(@RequestParam String sid){//使用@RequestParm 修饰符接收

        return sid+"服务器已收到";
    }

//http://localhost/receivePathValue/def456
    @GetMapping("receivePathValue/{sid}")
    @ResponseBody
    public String receivePathVaue(@PathVariable(name="sid" ) String sid){
        return sid+"服务器已收到";
    }
//提交的参数
//    {
//        "id":"id001",
//            "stuid":"stuid001",
//            "name":"测试姓名001"
//    }
   @PostMapping("receiveAnObject")
    @ResponseBody
    public Student reciveAnObject(@RequestBody Student student){ //注意接收参数的修饰符
        return student;
   }

//用于接收form表单提交的信息

   @PostMapping("receiveFormValue")
    @ResponseBody
    public Student recieveFormValue(Student student){
        return student;
   }


   @GetMapping("returnAnObjectList")
    @ResponseBody
    public List<Student> returnAnObjectList(){
       //泛型
        List<Student> sl=new ArrayList<>();

        for(int i=0;i<10;i++){
            Student s=new Student();
            s.setId("id"+i);
            s.setStuid("stuid"+i);
            s.setName("name"+i);
            sl.add(s);
        }

        return sl;

   }


   @PostMapping("receiveAnList")
    @ResponseBody
    public List<Student> reciveAnList(@RequestBody List<Student> sl){
        return sl;
   }












}
